package tan.reporting.ui.view.mediators {

import flash.events.MouseEvent;

import mx.events.MenuEvent;

import org.robotlegs.mvcs.Mediator;

import tan.reporting.ui.Main;
import tan.reporting.ui.events.IncreaseCountEvent;
import tan.reporting.ui.model.MenuClickModel;

public class MainMediator extends Mediator {

    [Inject] public var model:MenuClickModel;

    public function MainMediator() {
        super();
    }

    override public function onRegister():void {
        eventMap.mapListener(view.menuBar, MouseEvent.CLICK, onMenuClick, MouseEvent);
        eventMap.mapListener(eventDispatcher, IncreaseCountEvent.INCREASE_COMPLETE, onIncrease, IncreaseCountEvent);
    }

    private function get view():Main {
        return contextView as Main;
    }

    protected function onMenuClick(event:MenuEvent):void {
        dispatch(new IncreaseCountEvent(IncreaseCountEvent.INCREASE));
    }

    protected function onIncrease(event:IncreaseCountEvent):void {
        view.lblClickCount.text = "Clicks: " + model.count;   
    }
}

}